﻿using Domain.IServices;
using Domain.Models;
using Infrastructure.Events;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Domain.Events
{
    public class DomainEventHandler : IIntegrationEventHandler<DomainEvent>
    {
        private readonly IDomainService<GitLibaray> service;
        public DomainEventHandler(IDomainService<GitLibaray> service)
        {
            this.service = service ?? throw new ArgumentNullException(nameof(service));
        }
        public async Task HandlerAsync(DomainEvent @event, CancellationToken cancellationToken = default)
        {
            await service.AddSyncLog(@event.GitLibaray, @event.Message, cancellationToken);
        }
    }
}
